<template>
  <a-drawer
    :title="formInfo.id==undefined?'新增':'修改'"
    :maskClosable="true"
    :width="drawerWidth"
    placement="right"
    :closable="true"
    @close="handleCancel"
    :destroyOnClose="true"
    :visible="visible"
    style="height: calc(100% - 55px);overflow: auto;padding-bottom: 53px;">
    <a-spin :spinning="confirmLoading">
      <a-form-model
        ref="ruleForm"
        :model="formInfo"
        :label-col="$global.labelCol"
        :wrapper-col="$global.wrapperCol"
      >
            <a-row>
              <a-col :span="12">
            <a-form-model-item label="名称" prop="name" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.name" placeholder="请输入名称"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="" prop="dingdingUnionId" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.dingdingUnionId" placeholder="请输入"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="父级" prop="parentId" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.parentId" placeholder="请输入父级"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="联系人" prop="contact" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.contact" placeholder="请输入联系人"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="手机号" prop="mobile" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.mobile" placeholder="请输入手机号"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="地址" prop="address" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.address" placeholder="请输入地址"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="0部门 1学校 2 班级" prop="orgFlag">
              <a-select v-model="formInfo.orgFlag" placeholder="请选择0部门 1学校 2 班级">
                <a-select-option v-for="(item) in this.$sysDictOptions('orgFlag')" :key="item.k" :value="parseInt(item.k)">
                  {{ item.v }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="学年" prop="years" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.years" placeholder="请输入学年"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="系统编码" prop="departCode" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.departCode" placeholder="请输入系统编码"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="项目描述" prop="projectDesc" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.projectDesc" placeholder="请输入项目描述"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="简称" prop="shorter" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.shorter" placeholder="请输入简称"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="" prop="level" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.level" placeholder="请输入"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="省市区" prop="areaCode" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.areaCode" placeholder="请输入省市区"/>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="排序" prop="sortOrder" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.sortOrder" placeholder="请输入排序"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="状态 PS0筹备 PS1在建 PS2完工" prop="statusFlag">
              <a-select v-model="formInfo.statusFlag" placeholder="请选择状态 PS0筹备 PS1在建 PS2完工">
                <a-select-option v-for="(item) in this.$sysDictOptions('statusFlag')" :key="item.k" :value="parseInt(item.k)">
                  {{ item.v }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
                  <a-col :span="12">
            <a-form-model-item label="项目编码" prop="departSn" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.departSn" placeholder="请输入项目编码"/>
            </a-form-model-item>
          </a-col>
            </a-row>
                <a-row>
              <a-col :span="12">
            <a-form-model-item label="省市区名称（逗号分隔）" prop="areaData" :rules="$valid.required" :maxLength="50">
              <a-input v-model="formInfo.areaData" placeholder="请输入省市区名称（逗号分隔）"/>
            </a-form-model-item>
          </a-col>
                </a-row>
            <a-row>
            <a-col :span="24">
                <a-form-model-item  :labelCol="$global.labelTextAreaCol"  :wrapperCol="$global.wrapperTextAreaCol"  label="备注">
                    <a-input v-model="formInfo.remark" type="textarea"/>
                </a-form-model-item>
            </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
    <div class="drawer-bootom-button">
      <a-popconfirm title="确定放弃编辑？" @confirm="handleCancel" okText="确定" cancelText="取消">
        <a-button style="margin-right: .8rem">取消</a-button>
      </a-popconfirm>
      <a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
    </div>
  </a-drawer>
</template>

<script>
  import { getAction, postAction } from '@/api/manage'
  export default {
    name: 'EyeClassEdit',
    components: {
    },
    data () {
      return {
        visible: false,
        confirmLoading: false,
        formInfo: {
          name: undefined,
          dingdingUnionId: undefined,
          parentId: undefined,
          contact: undefined,
          mobile: undefined,
          address: undefined,
          orgFlag: undefined,
          years: undefined,
          createTime: undefined,
          departCode: undefined,
          remark: undefined,
          projectDesc: undefined,
          shorter: undefined,
          level: undefined,
          areaCode: undefined,
          sortOrder: undefined,
          statusFlag: undefined,
          departSn: undefined,
          areaData: undefined,
          wx: ''
        },
        drawerWidth: 800,
        url: {
          saveInfo: '/system/eyeClass/save',
          getInfo: '/system/eyeClass/info'
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit()
      },
      edit (record) {
        this.$objToOverride(this.formInfo, record)
        if (this.formInfo.id) {
          getAction(this.url.getInfo, { 'id': record.id }).then(res => {
            this.$nextTick(() => {
              this.formInfo = res.result.data
            })
          })
        }
        this.visible = true
      },
      // 确定
      handleSubmit () {
        // 触发表单验证
        this.confirmLoading = true
        this.$refs.ruleForm.validate(valid => {
          console.log(valid)
          if (valid) {
            postAction(this.url.saveInfo, this.formInfo).then(res => {
              this.$message.success(res.content)
              this.$emit('ok', this.formInfo)
              this.close()
            }).finally(() => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      // 关闭
      handleCancel () {
        this.close()
      },
      close () {
        this.$refs.ruleForm.resetFields()
        this.$objToReset(this.formInfo)
        this.$emit('close')
        this.visible = false
      },
      editorOk (val) {
        this.formInfo.content = val
      }
    }
  }
</script>
